package cate.game.chat;

import cate.game.role.friend.FriendChat;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

@NoteClass("离线聊天数据")
public class OfflinePrivateChatItem {
    @NoteField("聊天发起人信息")
    public ChatSenderInfo sender;

    @NoteField("聊天记录")
    public List<FriendChat> history = new ArrayList<>();

    public OfflinePrivateChatItem(ChatSenderInfo sender) {
        this.sender = sender;
    }

    public synchronized void addChat(ChatPublicItem item) {
        sender = item.sender;
        if (history.size() >= 100) {
            history.remove(0);
        }
        history.add(FriendChat.builder()
                .c(item.content)
                .p(item.params)
                .t(System.currentTimeMillis())
                .cid(item.contentId)
                .build());
    }
}
